﻿using App.Common;
using QxFramework.Core;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class EnemyUI : UIBase
{
    private string MonoName;
    public override void OnDisplay(object args)
    {
        base.OnDisplay(args);
        MonoName = args.ToString();
        canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
    }

    private void Update()
    {
        UpdateHp();
        UpdateMp();
        UpdateTips();
    }
    private void LateUpdate()
    {
        UpdateUIPosition();
    }

    float FalseHp;
    float FalseMp;
    float FalseLp;
    void UpdateHp()
    {
        HP hpData = GameMgr.Get<IMonoManager>().GetMono(MonoName).HPData;
        _gos["HpBar"].GetComponent<Slider>().value = ((float)hpData.HPValue) / ((float)hpData.HPCeiling);
        if (FalseHp < hpData.HPValue)
        {
            FalseHp = hpData.HPValue;
        }
        else
        {
            FalseHp -= 0.2f;
        }
        _gos["HpFalseBar"].GetComponent<Slider>().value = ((float)FalseHp) / ((float)hpData.HPCeiling);
    }
    void UpdateMp()
    {
        MP mpData = GameMgr.Get<IMonoManager>().GetMono(MonoName).MPData;
        if (GameMgr.Get<IMonoManager>().GetMono(MonoName).SkillList.Count <= 0)
        {
            return;
        }
         SkillMPData skillMPData = GameMgr.Get<IMonoManager>().GetMono(MonoName).SkillList[0].skillMPData;
        _gos["MpBar"].GetComponent<Slider>().value = ((float)mpData.MPValue) / ((float)mpData.MPCeiling);
        if (FalseMp < mpData.MPValue)
        {
            FalseMp = mpData.MPValue;
        }
        else
        {
            FalseMp -= 20f;
        }
        _gos["MpFalseBar"].GetComponent<Slider>().value = ((float)FalseMp) / ((float)mpData.MPCeiling);
    }
    void UpdateTips()
    {
        AttackTips tipsData = GameMgr.Get<IMonoManager>().GetMono(MonoName).AttackTipsData;
        if (GameMgr.Get<IMonoManager>().GetMono(MonoName).monoRealtimeStatus.AttackTips)
        {
            _gos["TipsBar"].SetActive(true);
            _gos["TipsFalseBar"].SetActive(true);
        }
        if (tipsData.CurrentValue <= 0)
        {
            _gos["TipsBar"].SetActive(false);
            _gos["TipsFalseBar"].SetActive(false);
        }
        if (tipsData.CurrentValue != 0)
        {
            _gos["TipsBar"].GetComponent<Slider>().value = ((float)tipsData.CurrentValue) / ((float)tipsData.ValueCeiling);
            _gos["TipsFalseBar"].GetComponent<Slider>().value = ((float)tipsData.CurrentValue) / ((float)tipsData.ValueCeiling);
        }
    }
    Canvas canvas;
    void UpdateUIPosition()
    {
        if (!GameMgr.Get<IMonoManager>().GetAllMono()._MonoList.ContainsKey(MonoName))
        {
            UIManager.Instance.Close(this);
            return;
        }
        if (GameMgr.Get<IMonoManager>().GetObj(GameMgr.Get<IMonoManager>().GetMono(MonoName)) == null)
        {
            return;
        }
        RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
            Camera.main.WorldToScreenPoint(GameMgr.Get<IMonoManager>().GetObj(GameMgr.Get<IMonoManager>().GetMono(MonoName)).transform.position),
            canvas.worldCamera, out Vector2 pos);
        _gos["Pivot"].GetComponent<RectTransform>().localPosition = new Vector3(pos.x, pos.y - 40, 0);
    }

}
